/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Animation.Animations;

import Scenery.BaseSprite;
import main.DumbMath;
import com.jme3.cinematic.MotionPath;
import com.jme3.cinematic.MotionPathListener;
import com.jme3.cinematic.events.MotionTrack;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import Animation.Animation;
import Animation.Animation;
import Scenery.BaseCharacter;
import Scenery.BaseSprite;
import main.DumbMath;

/*
 * 
 * @author: Ziden
 * 
 */

public class FootSteps extends Animation {
    
    // original positions
    Vector3f rfoot;
    Vector3f lfoot;
    
    // leg
    private float legSpeed = 0.25f;
    private float legAngle = 0f;
    private float inverseLegAngle = 0f;
    
    public FootSteps(BaseCharacter dude, int frames) {
        super(dude, 40); 
        storedValues = 4; // each leg and each leg heigh
        buildAnimation();
    }

    @Override
    public String getName() {
        return "Step";
    }

    @Override
    public void gotoInitialState() {
        // R FOOT 
        animationBody.getLfoot().setLocalTranslation(lfoot);
        animationBody.getRfoot().setLocalTranslation(rfoot);
        legAngle = 0;
        inverseLegAngle = 0;
        frame = 0;
    }

    @Override
    public void saveInitialState() {
        rfoot = animationBody.getRfoot().getLocalTranslation().clone();
        lfoot = animationBody.getLfoot().getLocalTranslation().clone();
    }

    @Override
    protected void buildFrame() {
       if(frame < maxFrame/4) {
           
           animationFrames[frame][2] = 0.2f; // angle
           animationFrames[frame][3] = 0.5f; // inverse
           
           legAngle += legSpeed;
           inverseLegAngle -= legSpeed;
       } 
       else if(frame >= maxFrame/4 && frame < (maxFrame*3)/4) {
           
           animationFrames[frame][2] = 0.5f;
           animationFrames[frame][3] = 0.2f;
           
           legAngle -= legSpeed;
           inverseLegAngle += legSpeed;
       }
       else if(frame >= (maxFrame*3)/4) {
           
          animationFrames[frame][2] = 0.2f;
          animationFrames[frame][3] = 0.5f;
           
          legAngle += legSpeed;
          inverseLegAngle -= legSpeed;
       }
       animationFrames[frame][0] = legAngle-1.5f;
       animationFrames[frame][1] = inverseLegAngle-1.5f;
    }

    @Override
    public void performFrame() {
         DumbMath.anglyRotate(animationFrames[frame][0],  animationFrames[frame][2], animationBody.getRfoot(), -0.3f);
         DumbMath.anglyRotate(animationFrames[frame][1],  animationFrames[frame][3], animationBody.getLfoot(), 0.3f); 
    }

    @Override
    protected float getCicleRunTime() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
